package net.flyinggroup.scst.loggingconsumer;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.function.context.PollableBean;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;
import reactor.core.publisher.Flux;

import java.time.Instant;
import java.util.function.Consumer;
import java.util.function.Supplier;

@SpringBootApplication
@Slf4j
public class LoggingConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(LoggingConsumerApplication.class, args);
    }

    @PollableBean
    public Supplier<Flux<Person>> emit() {
        return () -> {
            Person person = new Person();
            person.setName(Instant.now().toString());
            return Flux.just(person);
        };
    }
    @Bean
    public Consumer<Person> log() {
        return person -> log.info("Received: {}", person);
    }

    @Getter
    @Setter
    @ToString
    public static class Person {
        private String name;
    }
}